package org.coopac.controller.util;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.coopac.model.CoopacTipoCredito;
import org.primefaces.model.SelectableDataModel;

public class CreditoDataModel extends ListDataModel<CoopacTipoCredito> implements SelectableDataModel<CoopacTipoCredito> {  

	
    public CreditoDataModel() {
    }

    public CreditoDataModel(List<CoopacTipoCredito> data) {
        super(data);
    }
    
    //@Override
    public CoopacTipoCredito getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data
        
        @SuppressWarnings("unchecked")
		List<CoopacTipoCredito> CoopacTipoCreditos = (List<CoopacTipoCredito>) getWrappedData();
        
        for(CoopacTipoCredito CoopacTipoCredito : CoopacTipoCreditos) {
            if(CoopacTipoCredito.getNombre().equals(rowKey))
                return CoopacTipoCredito;
        }
        
        return null;
    }

    public Object getRowKey(CoopacTipoCredito CoopacTipoCredito) {
        return CoopacTipoCredito.getNombre();
    }
}
           